package com.ichart.html;

import java.util.regex.Pattern;


public abstract class Template<T> {
	protected Theme theme = new Theme();
	protected T object;
	protected Html html;
	public static Pattern SPLITROW = Pattern.compile("^(.*)$",Pattern.MULTILINE);
	
	
	public Template(){
		//this.theme.setJs(new String[]{"../js/jquery-1.7.2.min.js"});
		this.theme.setCss(new String[]{"../resources/style.css"});
		this.theme.setMeta(new String[]{
			"http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"",
			"http-equiv=\"Content-Style-Type\" content=\"text/css\""
		});
	}
	
	public String toHtml(T object){
		this.html = new Html();
		this.object = object;
		summary();
		detail();
		reference();
		return page();
	}
	
	/**
	 * 页面主体
	 * @return
	 * String
	 * create at 2012-4-27 下午03:24:43
	 * @author wanghe
	 */
	protected abstract String page();
	
	/**
	 * Component Summary
	 * void
	 * create at 2012-4-27 下午03:25:03
	 * @author wanghe
	 */
	protected abstract void summary();
	
	/**
	 * Component detail Configuration
	 * void
	 * create at 2012-4-27 下午03:25:19
	 * @author wanghe
	 */
	protected abstract void detail();
	
	/**
	 * the bottom reference
	 * void
	 * create at 2012-4-27 下午03:25:44
	 * @author wanghe
	 */
	protected abstract void reference();
	
	
	class Html{
		StringBuffer page = new StringBuffer();
		public void enterBr(Object s){
			page.append(s.toString());
			page.append("<br/>");
		}
		public void enter(Object s){
			page.append(s.toString());
			page.append(Theme.enter);
		}
		public void append(Object s){
			page.append(s.toString());
		}
		public String toString(){
			return page.toString();
		}
	}
}
